﻿using System;
using System.Collections.Generic;
using System.Text;
using JsonSharp;
using Barbar.MapReport.HtmlRender.Operations.ValueIndicators;
using JsonSharp.Collections;
using Barbar.MapReport.Common.Drawing.ValueIndicators;

namespace Barbar.MapReport.HtmlRender.Json {
  internal class ValueIndicatorAgregatorCollectionFactory : JsonFactory {
    private ValueIndicatorAgregatorCollection m_Agregators;
    private BaseProperties m_Properties;
    private string m_HandlerUrl;

    internal ValueIndicatorAgregatorCollectionFactory(ValueIndicatorAgregatorCollection agregators, BaseProperties properties, string handlerUrl) {
      if (agregators == null)
        throw new ArgumentNullException("agregators");
      if (properties == null)
        throw new ArgumentNullException("properties");
      if (String.IsNullOrEmpty(handlerUrl))
        throw new ArgumentNullException("handlerUrl");
      m_Agregators = agregators;
      m_Properties = properties;
      m_HandlerUrl = handlerUrl;
    }

    public override JsonValue ToJsonObject() {
      JsonArrays result = new JsonArrays();
      foreach (ValueIndicatorAgregator agregator in m_Agregators) {
        ValueIndicatorAgregatorFactory factory = new ValueIndicatorAgregatorFactory(agregator,m_Properties, m_HandlerUrl);
        result.Add(factory.ToJsonObject());
      }
      return result;
    }
  }
}
